{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Day of the Year"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: dayOfYear"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #一年中的第几天"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串&nbsp;<code>date</code> ，按 <code>YYYY-MM-DD</code> 格式表示一个 <a href=\"https://baike.baidu.com/item/公元/17855\" target=\"_blank\">现行公元纪年法</a> 日期。返回该日期是当年的第几天。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>date = \"2019-01-09\"\n",
    "<strong>输出：</strong>9\n",
    "<strong>解释：</strong>给定日期是2019年的第九天。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>date = \"2019-02-10\"\n",
    "<strong>输出：</strong>41\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>date.length == 10</code></li>\n",
    "\t<li><code>date[4] == date[7] == '-'</code>，其他的&nbsp;<code>date[i]</code>&nbsp;都是数字</li>\n",
    "\t<li><code>date</code> 表示的范围从 1900 年 1 月 1 日至 2019 年 12 月 31 日</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [day-of-the-year](https://leetcode.cn/problems/day-of-the-year/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [day-of-the-year](https://leetcode.cn/problems/day-of-the-year/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"2019-01-09\"', '\"2019-02-10\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        def dayOfYear(date: str) -> int:\n",
    "            dd = date.split('-')\n",
    "            day = 0\n",
    "            if int(dd[0]) % 400 == 0 or (int(dd[0]) % 4 == 0 and int(dd[0]) % 100 != 0):  # 闰年\n",
    "                days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "                day += sum(days[:int(dd[1]) - 1])\n",
    "                day += int(dd[2])\n",
    "            else:\n",
    "                days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "                day += sum(days[:int(dd[1]) - 1])\n",
    "                day += int(dd[2])\n",
    "            return day\n",
    "\n",
    "        days = 0\n",
    "        for yy in range(1971, year):\n",
    "            days += dayOfYear(str(yy) + \"-12-31\")\n",
    "        days += dayOfYear(str(year) + \"-\" + str(month) + \"-\" + str(day))\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        return week[(days + 3) % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split('-')]\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "        ans = sum(amount[:month-1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year,month,day=[int(x)for x in date.split(\"-\")]\n",
    "        amount=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        if year%400==0 or (year%4==0 and year%100!=0):\n",
    "            amount[1]+=1\n",
    "        ans=sum(amount[:month-1])\n",
    "        return ans+day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        y, m, d = map(int, date.split('-'))\n",
    "        dom = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if y % 4 == 0 and y % 100 != 0 or y % 400 == 0:\n",
    "            dom[2] = 29\n",
    "        return sum(dom[:m]) + d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year,month,day =[int(x) for x in date.split('-')]#以'-'为分隔符分割字符串\n",
    "        amount =[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        if year%400==0 or (year%4==0 and year%100!=0):\n",
    "            amount[1]+=1\n",
    "\n",
    "        ans = sum(amount[:month-1])\n",
    "        return ans+day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year,month,day = int(date[0:4]),int(date[5:7]),int(date[8:10])\n",
    "        month_30 = [4,6,9,11]\n",
    "        feb = 28\n",
    "        ans = 0\n",
    "        if year % 4 == 0:\n",
    "            if year % 100 == 0:\n",
    "                if year % 400 == 0:\n",
    "                    feb = 29\n",
    "            else:\n",
    "                feb = 29\n",
    "        for i in range(1,month):\n",
    "            if i in month_30:\n",
    "                ans += 30\n",
    "            elif i == 2:\n",
    "                ans += feb\n",
    "            else:\n",
    "                ans += 31\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        ans = 0\n",
    "        year = int(date[0:4])\n",
    "        month = int(date[5:7])\n",
    "        day = int(date[8:10])\n",
    "        s = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        # 检测闰年\n",
    "        if (year % 4 == 0 and year % 100 or year % 400 == 0) and month > 2:\n",
    "            ans += 1\n",
    "        month -= 1\n",
    "        while month:\n",
    "            ans += s[month - 1]\n",
    "            month -= 1\n",
    "        ans += day\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        Y = int(date[:4])\n",
    "        M = int(date[5:7])\n",
    "        D = int(date[-2:])\n",
    "        MD = [0, 31 ,59 ,90 ,120 ,151 ,181 ,212 ,243 ,273 ,304 ,334]\n",
    "        now = 0\n",
    "        m = M-1\n",
    "        now = MD[m]+D\n",
    "        if (Y % 4 == 0 and Y % 100 != 0) or Y % 400 == 0:\n",
    "            if M > 2:\n",
    "                now+=1\n",
    "        return now"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        Y = int(date[:4])\n",
    "        M = int(date[5:7])\n",
    "        D = int(date[-2:])\n",
    "        MD = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        MD1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        now = 0\n",
    "        if M == 1:\n",
    "            now += D\n",
    "            return now\n",
    "        else:\n",
    "            if (Y % 4 == 0 and Y % 100 != 0) or Y % 400 == 0:\n",
    "                for i in range(0, M - 1):\n",
    "                    now = now + MD[i]\n",
    "                now += D\n",
    "                return now\n",
    "            else:\n",
    "                for i in range(0, M - 1):\n",
    "                    now = now + MD1[i]\n",
    "                now += D\n",
    "                return now\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year = int(date[:4])\n",
    "        month = int(date[5:7])\n",
    "        day = int(date[8:])\n",
    "        flag = None\n",
    "        res = 0\n",
    "        t_1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        t_2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:\n",
    "            flag = True\n",
    "        if flag:\n",
    "            for i in range(1, month):\n",
    "                day += t_2[i - 1]\n",
    "            return res + day\n",
    "        elif not flag:\n",
    "            for i in range(1, month):\n",
    "                day += t_1[i - 1]\n",
    "            return res + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        a=int(date[0:4])\n",
    "        b=int(date[5:7])\n",
    "        c=int(date[8:10])\n",
    "        t=c\n",
    "        k=0\n",
    "        if a%4==0:\n",
    "            if a%100!=0:\n",
    "                k=1\n",
    "            else:\n",
    "                if a%400==0:\n",
    "                    k=1\n",
    "        if k==1 and b>2:\n",
    "            t+=1\n",
    "        s=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        i=0\n",
    "        while b-1!=0:\n",
    "            t+=s[i]\n",
    "            i+=1\n",
    "            b-=1\n",
    "        return t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        months1=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        months2=[31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "        year=int(date[0:4])\n",
    "        month=int(date[5:7])\n",
    "        day=int(date[8:10])\n",
    "        if (year%4==0 and year%100!=0) or year%400==0:\n",
    "            return sum(months2[0:month-1])+day\n",
    "        return sum(months1[0:month-1])+day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        return int((datetime.datetime.strptime(date, \"%Y-%m-%d\")).strftime('%j'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        dd = date.split('-')\n",
    "        day = 0\n",
    "        if int(dd[0])%400==0 or (int(dd[0])%4==0 and int(dd[0])%100!=0):#闰年\n",
    "            days = [31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "            day += sum(days[:int(dd[1])-1])\n",
    "            day += int(dd[2])\n",
    "        else:\n",
    "            days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "            day += sum(days[:int(dd[1])-1])\n",
    "            day += int(dd[2])\n",
    "        return day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        days = [31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        date = list(date.split('-'))\n",
    "        if (int(date[0])%4==0 and int(date[0])%100!=0) or int(date[0])%400==0:days[1]=29        \n",
    "        res=sum(days[:int(date[1])-1])+int(date[2])\n",
    "        return res\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str)->int:\n",
    "        year, month, day = date.split('-')\n",
    "        year, month, day = int(year), int(month), int(day)\n",
    "        dnums = [0,31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        s = 0\n",
    "        for i in range(month):\n",
    "            s += dnums[i]\n",
    "        s += day\n",
    "        #闰年，再加1\n",
    "        if (year%400==0) or (year%4==0 and year%100 != 0):\n",
    "            if month > 2:\n",
    "                s += 1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        s=date.split(\"-\")\n",
    "        map1=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        map2=[0,31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "        if int(s[0])%400==0 or int(int(s[0])%4==0 and not int(s[0])%100==0):\n",
    "            day=0\n",
    "            for i in range(1,int(s[1])):\n",
    "                day+=map2[i]\n",
    "            return day+int(s[2])\n",
    "        else:\n",
    "            day=0\n",
    "            for i in range(1,int(s[1])):\n",
    "                day+=map1[i]\n",
    "            return day+int(s[2])\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year,month,day = [int(i) for i in date.split('-')]\n",
    "        days = [31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        rs = 0\n",
    "        for i in range(month-1):\n",
    "            rs += days[i]\n",
    "        if (year%4==0 and year%100!=0 or year%400==0) and month>2:\n",
    "            rs += 1\n",
    "        rs += day\n",
    "        return rs\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isLeapYear(self, year):\n",
    "        return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)\n",
    "\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = map(int, date.split(\"-\"))\n",
    "        days_in_month = [\n",
    "            0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31\n",
    "        ]\n",
    "\n",
    "        if self.isLeapYear(year):\n",
    "            days_in_month[2] = 29\n",
    "\n",
    "        day_count = sum(days_in_month[i] for i in range(1, month))\n",
    "        day_count += day\n",
    "\n",
    "        return day_count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year,month,day = [int(x) for x in date.split('-')]\n",
    "        amount = [31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        if year % 400 == 0 or (year % 4 ==0 and year %100 !=0):\n",
    "            amount[1] += 1\n",
    "        ans = sum(amount[:month-1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        date = list(map(int, date.split('-')))\n",
    "\n",
    "        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        rnt = sum(days[:date[1]-1]) + date[2]\n",
    "\n",
    "        if date[1] > 2 and ((date[0] % 4 == 0 and date[0] % 100 != 0) or date[0] % 400 == 0) :\n",
    "            rnt += 1\n",
    "        return rnt\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year= int(date[0:4])\n",
    "        months = [31, 28,31,30,31,30,31,31,30,31,30,31]\n",
    "        month = int(date[5:7])\n",
    "        days = sum([months[i] for i in range(0,month-1) ])\n",
    "        isRun = False\n",
    "        if year%400==0 or(year%4==0 and year%100!=0):\n",
    "            isRun = True\n",
    "        if isRun and month>2:\n",
    "            return days+int(date[8:10])+1\n",
    "        else:\n",
    "            return days+int(date[8:10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        y, m, d = [int(x) for x in date.split(\"-\")]\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if y % 400==0 or (y %4 == 0 and y%100 != 0):\n",
    "            amount[1] += 1\n",
    "        ans = sum(amount[:m -1])\n",
    "        return ans + d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        y, m, d = map(int, date.split(\"-\"))\n",
    "        if y % 400 == 0 or (y % 100 != 0 and y % 4 == 0):\n",
    "            months[2] = 29\n",
    "        return sum(months[:m]) + d\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        lst = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        d = date.split(\"-\")\n",
    "        y, m, d = int(d[0]), int(d[1]), int(d[2])\n",
    "        ans = 0\n",
    "        if m > 2:      # 需要注意月份要大于2月才能加上这个闰年的天数\n",
    "            if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:\n",
    "                ans += 1\n",
    "        ans += sum(lst[:m - 1]) + d\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        month=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        y=int(date[0:4])\n",
    "        a=int(date[5:7])\n",
    "        b=int(date[8:10])\n",
    "        sum=0\n",
    "        if y%4==0 and y%100!=0 or y%400==0:\n",
    "            month[1]+=1\n",
    "        for i in range(a-1):\n",
    "            sum += month[i]\n",
    "        sum += b\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isLeapYear(self, year: int) -> bool:\n",
    "        return year % 4 == 0 and (year % 400 == 0 or year % 100 != 0)\n",
    "\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        daysOfMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        [year, month, day] = date.split('-')\n",
    "        days = 0\n",
    "        for i in range(int(month) - 1):\n",
    "            days += daysOfMonth[i]\n",
    "        return days + int(day) + (self.isLeapYear(int(year)) and int(month) > 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year = date.split('-', 1)[0]\n",
    "        return (datetime.datetime.fromisoformat(date) - datetime.datetime.fromisoformat(year+'-01-01')).days + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        daysOfMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        leapYearPlus = lambda x: 1 if (x % 4 == 0 and x % 100 != 0 or x % 400 == 0) else 0\n",
    "        year = int(date[:4])\n",
    "        month = int(date[5:7])\n",
    "        day = int(date[8:10])\n",
    "        return sum(daysOfMonth[:month]) + day + (leapYearPlus(year) if month > 2 else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "        months = [31, 28,31,30,31,30,31,31,30,31,30,31]\n",
    "        \n",
    "        if year%400==0 or(year%4==0 and year%100!=0):\n",
    "            months[1]+=1\n",
    "        ans = sum(months[:month-1])\n",
    "        return ans+day\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        days=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        year,month,day=[int(i) for i in date.split(\"-\")]\n",
    "        if (year%4==0 and year%100!=0 ) or (year%400==0):\n",
    "            days[1]+=1\n",
    "        ans=sum(days[:month - 1])\n",
    "        return ans+day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        lis = date.split('-')\n",
    "        year = int(lis[0])\n",
    "        mon = {1:0,2:31,3:59,4:90,5:120,6:151,7:181,8:212,9:243,10:273,11:304,12:334}\n",
    "        day = 0\n",
    "        if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):\n",
    "            if int(lis[1]) > 2:\n",
    "                key = int(lis[1])\n",
    "                day = mon[key] + int(lis[2]) + 1\n",
    "            else:\n",
    "                key = int(lis[1])\n",
    "                day = mon[key] + int(lis[2])\n",
    "        else:\n",
    "            key = int(lis[1])\n",
    "            day = mon[key] + int(lis[2])\n",
    "        return day\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        result=0\n",
    "        y=int(date[0:4])\n",
    "        m=int(date[5:7])\n",
    "        d=int(date[8:])\n",
    "        days=[0]+list(accumulate([31,28,31,30,31,30,31,31,30,31,30,31]))\n",
    "        if m>2 and (y%400==0 or (y%4==0 and y%100 !=0)):\n",
    "            result=days[m-1]+d+1\n",
    "        else:\n",
    "            result=days[m-1]+d\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        y, m, d = date.split(\"-\")\n",
    "        \n",
    "        m2 = 28\n",
    "        y = int(y)\n",
    "        if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:\n",
    "            m2 = 29\n",
    "\n",
    "        mon_dict = {\n",
    "            \"0\": 0,\n",
    "            \"1\": 31,\n",
    "            \"2\": m2,\n",
    "            \"3\": 31,\n",
    "            \"4\": 30,\n",
    "            \"5\": 31,\n",
    "            \"6\": 30,\n",
    "            \"7\": 31,\n",
    "            \"8\": 31,\n",
    "            \"9\": 30,\n",
    "            \"10\": 31,\n",
    "            \"11\": 30,\n",
    "            \"12\": 31\n",
    "        }\n",
    "\n",
    "        count = 0\n",
    "        for i in range(int(m)):\n",
    "            count += mon_dict[str(i)]\n",
    "        count += int(d)\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        y = int(date[5:7])-1\n",
    "        x = int(date[8:])+30*y\n",
    "        print(x, y)\n",
    "        if y > 0:\n",
    "            x += 1\n",
    "        if y > 1: \n",
    "            z = int(date[:4])\n",
    "            x -= 2\n",
    "            if z%400 == 0 or z%100!=0 and z%4==0:\n",
    "                x += 1\n",
    "        if y > 2:\n",
    "            x += 1\n",
    "        if y > 4:\n",
    "            x += 1\n",
    "        if y > 6:\n",
    "            x += 1\n",
    "        if y > 7:\n",
    "            x += 1\n",
    "        if y > 9:\n",
    "            x += 1\n",
    "        if y > 11:\n",
    "            x += 1\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        d=date.split('-')\n",
    "        year,month,day=int(d[0]),int(d[1]),int(d[2])\n",
    "        month_days=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        if year!=1900 and year%4==0:\n",
    "            month_days[2]=29\n",
    "        result=sum(month_days[:month])+day\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year,month,day=[int (x) for x in date.split(\"-\")]\n",
    "        amount=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year%400==0 or (year%4==0 and year%100!=0):\n",
    "            amount[1]+=1\n",
    "        ans=sum(amount[:month-1])\n",
    "        return ans+day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        start=datetime.date(int(date[:4]),1,1)\n",
    "        end=datetime.date(int(date[:4]),int(date[5:7]),int(date[8:]))\n",
    "        s=datetime.timedelta(days=1)\n",
    "        ans=0\n",
    "        while start<=end:\n",
    "            start+=s\n",
    "            ans+=1\n",
    "        return ans\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        days = [0] + list(accumulate([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]))\n",
    "        y, m, d = int(date[:4]), int(date[5:7]), int(date[-2:])\n",
    "        if m > 2 and (y % 400 == 0 or (y % 4 == 0 and y % 100 != 0)):\n",
    "            return days[m - 1] + d + 1\n",
    "        return days[m - 1] + d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        prefix = [0]\n",
    "        for d in daysInMonth:\n",
    "            prefix.append(d + prefix[-1])\n",
    "\n",
    "        def isSpecialYear(n):\n",
    "            if n % 4 == 0:\n",
    "                if n % 100 == 0:\n",
    "                    if n % 400 == 0:\n",
    "                        return True\n",
    "                    return False\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        year, month, day = date.split('-')\n",
    "        year, month, day = int(year), int(month), int(day)\n",
    "        ans = prefix[month - 1] + day\n",
    "        if isSpecialYear(year) and month > 2:\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        al=date.split('-')\n",
    "        if (int(al[0])%4==0 and int(al[0])%100!=0) or int(al[0])%400==0 :\n",
    "            dl=[31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "        else:\n",
    "            dl=[31,28,31,30,31,30,31,31,30,31,30,31]       \n",
    "\n",
    "        return sum(dl[:int(al[1])-1])+int(al[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        a1=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        a2=[0,31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "        x=int(date[:4])\n",
    "        if date[5]=='0':\n",
    "            y=int(date[6])\n",
    "        else:\n",
    "            y=int(date[5:7])\n",
    "        if date[-2]=='0':\n",
    "            z=int(date[-1])\n",
    "        else:\n",
    "            z=int(date[-2:])\n",
    "        r=0\n",
    "        if x==1900 or x%4!=0:#if elif 交插范围 result\n",
    "            if y==1:\n",
    "                r=z\n",
    "            else:\n",
    "                for i in range(1,y):\n",
    "                    r+=a1[i]\n",
    "                r+=z\n",
    "        elif x!=1900 and x%4==0:\n",
    "            if y==1:\n",
    "                r=z\n",
    "            else:\n",
    "                for i in range(1,y):\n",
    "                    r+=a2[i]\n",
    "                r+=z\n",
    "        return r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        return (datetime.datetime.fromisoformat(date) - datetime.datetime.fromisoformat(date.split('-', 1)[0]+'-01-01')).days + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x  in date.split(\"-\")]\n",
    "        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            days[1] += 1\n",
    "        ans = sum(days[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        days = [0,31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        date = date.split(\"-\")\n",
    "        if (int(date[0])%4 == 0 and int(date[0])%100 != 0) or (int(date[0])%400==0):\n",
    "            days[2] = 29\n",
    "        month = int(date[1])\n",
    "        return sum(days[:month])+int(date[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        leap = [0, 31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "        month = [0, 31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        date_arr = date.split(\"-\")\n",
    "        day_count = 0\n",
    "        \n",
    "        for i in range(int(date_arr[1])):\n",
    "            if self.leap(int(date_arr[0])):\n",
    "                day_count += leap[i]\n",
    "            else:\n",
    "                day_count += month[i]\n",
    "        day_count += int(date_arr[2])\n",
    "\n",
    "        return day_count\n",
    "    def leap(self, n):\n",
    "        if (n % 100 != 0 and n % 4 == 0) or n % 400 == 0 :\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        import calendar\n",
    "        day_res = []\n",
    "        year = date.split('-')[0]\n",
    "        mouth = date.split('-')[1]\n",
    "        for i in range(1,int(mouth)):\n",
    "            days = calendar.monthrange(int(year), int(i))[1]\n",
    "            day_res.append(days)\n",
    "        if len(day_res) ==0:\n",
    "            return int(date.split('-')[2])\n",
    "        else:\n",
    "            return sum(day_res) + int(date.split('-')[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        y=int(date[:4])\n",
    "        m=int(date[5:7])\n",
    "        d=int(date[8:])\n",
    "        if (y%4==0 and y%100!=0 ) or y%400==0:\n",
    "            flag=1\n",
    "        else:\n",
    "            flag=2 \n",
    "        count=0\n",
    "        for i in range(1,m):\n",
    "            if i in [1,3,5,7,8,10,12]:\n",
    "                count+=31\n",
    "            elif i==2 and flag==1:\n",
    "                count+=29\n",
    "            elif i==2 and flag==2:\n",
    "                count+=28\n",
    "            else:\n",
    "                count+=30\n",
    "        return count+d\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        return int((datetime.datetime.strptime(date, \"%Y-%m-%d\")).strftime('%j'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "      y,m,d=(int(x) for x in date.split('-'))\n",
    "      am=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "      if (y%400==0) or (y%4==0 and y%100!=0):\n",
    "        am[1]+=1\n",
    "      ans=sum(am[:m-1])\n",
    "      return ans+d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "\n",
    "        a1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "   \n",
    "        data = date.split(\"-\")\n",
    "        year = (int(data[0]))\n",
    "        mounth = (int(data[1]))\n",
    "        day = (int(data[2]))\n",
    "        if mounth > 1:\n",
    "            days = sum(a1[0:mounth - 1]) + int(data[2])\n",
    "        else:\n",
    "            days = int(data[2])\n",
    "        \n",
    "        if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):\n",
    "            if mounth > 2:\n",
    "                days += 1            \n",
    "        \n",
    "        return days\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        year, month, day = [int(x) for x in date.split(\"-\")]\n",
    "\n",
    "        amount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "            amount[1] += 1\n",
    "\n",
    "        ans = sum(amount[:month - 1])\n",
    "        return ans + day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def dayOfYear(self, date: str) -> int:\r\n",
    "        import datetime\r\n",
    "        today = datetime.date.fromisoformat(date)\r\n",
    "        firstday = datetime.date(today.year, 1, 1)\r\n",
    "\r\n",
    "        return today.toordinal() - firstday.toordinal() + 1\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        return int((datetime.datetime.strptime(date, \"%Y-%m-%d\")).strftime('%j'))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def dayOfYear(self, date: str) -> int:\r\n",
    "        days = [0,31,28,31,30,31,30,31,31,30,31,30,31]\r\n",
    "        res = 0\r\n",
    "        year, month, day = map(int, date.split('-'))\r\n",
    "        # 判断闰年\r\n",
    "        if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):\r\n",
    "            days[2] = 29\r\n",
    "        res = sum(days[:month]) + day\r\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date: str) -> int:\n",
    "        from datetime import datetime\n",
    "        date = datetime.strptime(date, \"%Y-%m-%d\")\n",
    "        return date.timetuple().tm_yday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfYear(self, date):\n",
    "        \"\"\"\n",
    "\n",
    "        \"\"\"\n",
    "        #处理异常情况\n",
    "        if date == None or len(date) == 0:\n",
    "            return -1\n",
    "\n",
    "        #处理字符串, 得到年月日\n",
    "        year_str, month_str, day_str = date[:4], date[5: 7], date[8:]\n",
    "        year = self.convertStr2Int(year_str)\n",
    "        month = self.convertStr2Int(month_str)\n",
    "        day = self.convertStr2Int(day_str)\n",
    "\n",
    "        #判断该年是否是闰年\n",
    "        flag = self.isLeapYear(year)\n",
    "        month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        if flag:\n",
    "            month_days[2] += 1\n",
    "\n",
    "        #计算月份的前缀数组\n",
    "        pre_month_days = [0 for _ in range(13)]\n",
    "        for i in range(2, 13):\n",
    "            pre_month_days[i] = pre_month_days[i - 1] + month_days[i - 1]\n",
    "\n",
    "        #计算最终第几天\n",
    "        return pre_month_days[month] + day \n",
    "\n",
    "    def isLeapYear(self, year):\n",
    "        \"\"\"\n",
    "        判断概念是否是闰年\n",
    "        Args:\n",
    "            year (int):\n",
    "        \n",
    "        \"\"\"\n",
    "        #能被400整除 or (能被4整除但不能被100整除)\n",
    "        if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):\n",
    "            return True \n",
    "        else:\n",
    "            return False \n",
    "        \n",
    "    def convertStr2Int(self, s):\n",
    "        \"\"\"\n",
    "        将字符串形式的数字转化为数字\n",
    "        Args:\n",
    "            s(str):\n",
    "        returns (int): \n",
    "        \"\"\"\n",
    "        n = len(s)\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            ans = 10 * ans + (ord(s[i]) - ord('0'))\n",
    "        \n",
    "        return ans \n",
    "    \n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
